import pathlib
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QTableWidgetItem, QApplication
from PyQt5.QtCore import QTranslator
from classes.engine import Engine
from ui_py.page1_ui import Main_Ui
from temp import Excel, ReadExcel
from grap import *
from expert import Expert
from error import Error
from dataExpert import Data
import json
from validation import validation
class Page1(QtWidgets.QWidget, Main_Ui):
    engine = Engine()
    def __init__(self):
        QtWidgets.QWidget.__init__(self)
        self.setupUi(self)
        self.expert = Expert()
        self.data = Data()
        self.err = Error()
        with open('lang.json', encoding='utf-8') as file:
            data = json.load(file)
        if data['lang'] != "":
            self.trans = QTranslator(self)
            self.trans.load('translate/' + 'page1')
            _app = QApplication.instance() # получить экземпляр приложения
            _app.installTranslator(self.trans)
        self.err.clear = 0
        self.Conrod = 0
        if data['lang'] != "":
            page = data['en']['page1']
            self.comboBox_3.addItem(page['type_engine'])
            self.comboBox_2.addItem(page['engine_one'], 1)
            self.comboBox_2.addItem(page['engine_two'], 2)
            self.comboBox_2.addItem(page['type_conrod'])
            self.comboBox_3.setCurrentText(page['type_engine'])
            self.comboBox_2.setCurrentText(page['type_conrod'])
            self.comboBox_3.addItem(page['conrod_one'], 1)
            self.comboBox_3.addItem(page['conrod_two'], 2)
            try:
                self.comboBox_3.blockSignals(True)
                self.Conrod = self.data.excel['Conrod']
                if self.Conrod == 1:
                    self.comboBox_3.setCurrentText(page['conrod_one'])
                elif self.Conrod == 2:
                    self.comboBox_3.setCurrentText(page['conrod_two'])
                self.comboBox_3.blockSignals(False)
            except:
                pass
            try:
                self.comboBox_2.blockSignals(True)
                if self.data.excel['kd'] == 1:
                    self.comboBox_2.setCurrentText(page['engine_one'])
                elif self.data.excel['kd'] == 2:
                    self.comboBox_2.setCurrentText(page['engine_two'])
                self.comboBox_2.blockSignals(False)
            except:
                pass
        else:
            self.comboBox_3.addItem("Выберите способ")
            self.comboBox_2.addItem("Бензиновый", 1)
            self.comboBox_2.addItem("Дизельный", 2)
            self.comboBox_2.addItem("Выберите тип")
            self.comboBox_3.setCurrentText("Выберите способ")
            self.comboBox_2.setCurrentText("Выберите тип")
            self.comboBox_3.addItem('Приведенные массы', 1)
            self.comboBox_3.addItem('Масса и моменты', 2)
            self.tableWidget.blockSignals(True)
            try:
                self.comboBox_3.blockSignals(True)
                self.Conrod = self.data.excel['Conrod']
                if self.Conrod == 1:
                    self.comboBox_3.setCurrentText("Приведенные массы")
                elif self.Conrod == 2:
                    self.comboBox_3.setCurrentText("Масса и моменты")
                self.comboBox_3.blockSignals(False)
            except:
                pass
            try:
                self.comboBox_2.blockSignals(True)
                if self.data.excel['kd'] == 1:
                    self.comboBox_2.setCurrentText("Бензиновый")
                elif self.data.excel['kd'] == 2:
                    self.comboBox_2.setCurrentText("Дизельный")
                self.comboBox_2.blockSignals(False)
            except:
                pass
        self.comboBox_3.currentIndexChanged.connect(self.conrod)
        self.comboBox_2.currentIndexChanged.connect(self.type_fuel)
        self.comboBox.currentIndexChanged.connect(self.cylinder)
        self.comboBox.blockSignals(True)
        if data['lang'] != "":
            self.comboBox.addItem("The order of cylinders")
            self.comboBox.setCurrentText("The order of cylinders")
        else:
            self.comboBox.addItem("Порядок работы цилиндров")
            self.comboBox.setCurrentText("Порядок работы цилиндров")
        if self.engine.cil == "L3":
            self.comboBox.addItem("1-3-2", 1)
            self.comboBox.addItem("1-2-3", 2)
        elif self.engine.cil == "L4":
            self.comboBox.addItem("1-2-4-3", 1)
            self.comboBox.addItem("1-3-4-2", 2)
        elif self.engine.cil == "L6":
            self.comboBox.addItem("1-5-3-6-2-4", 1)
            self.comboBox.addItem("1-4-2-6-3-5", 2)
        elif self.engine.cil == "V6":
            self.comboBox.addItem("1-4-2-5-3-6", 1)
            self.comboBox.addItem("1-6-3-5-2-4", 2)
        elif self.engine.cil == "V8":
            self.comboBox.addItem("1-5-4-2-6-3-7-8", 1)
            self.comboBox.addItem("1-5-7-2-6-3-4-8", 2)
            self.comboBox.addItem("1-8-7-2-6-5-4-3", 3)
        elif self.engine.cil == "V12":
            self.comboBox.addItem("1-12-5-8-3-10-6-7-2-11-4-9", 1)
            self.comboBox.addItem("1-7-5-11-3-9-6-12-2-8-4-10", 2)
        self.comboBox.blockSignals(False)
        try:
            self.comboBox.blockSignals(True)
            if self.engine.cil == "L3":
                if self.data.excel['iwar'] == 1:
                    self.comboBox.setCurrentText("1-3-2")
                elif self.data.excel['iwar'] == 2:
                    self.comboBox.setCurrentText("1-2-3")
            elif self.engine.cil == "L4":
                if self.data.excel['iwar'] == 1:
                    self.comboBox.setCurrentText("1-2-4-3")
                elif self.data.excel['iwar'] == 2:
                    self.comboBox.setCurrentText("1-3-4-2")
            elif self.engine.cil == "L6":
                if self.data.excel['iwar'] == 1:
                    self.comboBox.setCurrentText("1-5-3-6-2-4")
                elif self.data.excel['iwar'] == 2:
                    self.comboBox.setCurrentText("1-4-2-6-3-5")
            elif self.engine.cil == "V6":
                if self.data.excel['iwar'] == 1:
                    self.comboBox.setCurrentText("1-4-2-5-3-6")
                elif self.data.excel['iwar'] == 2:
                    self.comboBox.setCurrentText("1-6-3-5-2-4")
            elif self.engine.cil == "V8":
                if self.data.excel['iwar'] == 1:
                    self.comboBox.setCurrentText("1-5-4-2-6-3-7-8")
                elif self.data.excel['iwar'] == 2:
                    self.comboBox.setCurrentText("1-5-7-2-6-3-4-8")
                elif self.data.excel['iwar'] == 3:
                    self.comboBox.setCurrentText("1-8-7-2-6-5-4-3")
            elif self.engine.cil == "V12":
                if self.data.excel['iwar'] == 1:
                    self.comboBox.setCurrentText("1-12-5-8-3-10-6-7-2-11-4-9")
                elif self.data.excel['iwar'] == 2:
                    self.comboBox.setCurrentText("1-7-5-11-3-9-6-12-2-8-4-10")
            self.comboBox.blockSignals(False)
        except:
            pass
    
        if self.engine.cil == "V6" or self.engine.cil == "V8" or self.engine.cil == "V12":
            row = self.tableWidget.rowCount()
            self.tableWidget.insertRow(row)
            if data['lang'] != "":
                page = data['en']['page1']
                self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][0]))
            else:
                self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Угол развала цилиндров; RCIL"))
            try:
                value = str(self.data.excel['RCIL'])
            except:
                value = ""
            self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
            if data['lang'] != "":
                self.tableWidget.setItem(row, 1, QTableWidgetItem("deg"))
            else:
                self.tableWidget.setItem(row, 1, QTableWidgetItem("град"))

        row = self.tableWidget.rowCount()
        self.tableWidget.insertRow(row)
        if data['lang'] != "":
            page = data['en']['page1']
            self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][1]))
        else:
            self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Степень сжатия; edw"))
        try:
            value = str(self.data.excel['edw'])
        except:
            value = ""
        self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
        self.tableWidget.setItem(row, 1, QTableWidgetItem("-"))
        row = self.tableWidget.rowCount()
        self.tableWidget.insertRow(row)
        if data['lang'] != "":
            page = data['en']['page1']
            self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][2]))
        else:
            self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Диаметр цилиндра; DZ"))
        try:
            value = str(self.data.excel['dz'])
        except:
            value = ""
        self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
        if data['lang'] != "":
            self.tableWidget.setItem(row, 1, QTableWidgetItem("mm"))
        else:
            self.tableWidget.setItem(row, 1, QTableWidgetItem("мм"))
        row = self.tableWidget.rowCount()
        self.tableWidget.insertRow(row)
        if data['lang'] != "":
            page = data['en']['page1']
            self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Crank Throw radius; r"))
        else:
            self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Радиус кривошипа; r"))
        try:
            value = str(self.data.excel['r'])
        except:
            value = ""
        self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
        if data['lang'] != "":
            self.tableWidget.setItem(row, 1, QTableWidgetItem("mm"))
        else:
            self.tableWidget.setItem(row, 1, QTableWidgetItem("мм"))
        row = self.tableWidget.rowCount()
        self.tableWidget.insertRow(row)
        if data['lang'] != "":
            page = data['en']['page1']
            self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][3]))
        else:
            self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Длина шатуна; l"))
        try:
            value = str(self.data.excel['l'])
        except:
            value = ""
        self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
        if data['lang'] != "":
            self.tableWidget.setItem(row, 1, QTableWidgetItem("mm"))
        else:
            self.tableWidget.setItem(row, 1, QTableWidgetItem("мм"))
        row = self.tableWidget.rowCount()
        self.tableWidget.insertRow(row)
        if data['lang'] != "":
            page = data['en']['page1']
            self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][4]))
        else:
            self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Масса поршня; MSP"))
        try:
            value = str(self.data.excel['MSP'])
        except:
            value = ""
        self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
        if data['lang'] != "":
            self.tableWidget.setItem(row, 1, QTableWidgetItem("kg"))
        else:
            self.tableWidget.setItem(row, 1, QTableWidgetItem("кг"))
        row = self.tableWidget.rowCount()
        self.tableWidget.insertRow(row)
        if data['lang'] != "":
            page = data['en']['page1']
            self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][5]))
        else:
            self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Масса поршневого пальца; MSF"))
        try:
            value = str(self.data.excel['MSF'])
        except:
            value = ""
        self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
        if data['lang'] != "":
            self.tableWidget.setItem(row, 1, QTableWidgetItem("kg"))
        else:
            self.tableWidget.setItem(row, 1, QTableWidgetItem("кг"))
        row = self.tableWidget.rowCount()
        self.tableWidget.insertRow(row)
        if data['lang'] != "":
            page = data['en']['page1']
            self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][6]))
        else:
            self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Масса комплекта поршневых колец; MSR"))
        try:
            value = str(self.data.excel['MSR'])
        except:
            value = ""
        self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
        if data['lang'] != "":
            self.tableWidget.setItem(row, 1, QTableWidgetItem("kg"))
        else:
            self.tableWidget.setItem(row, 1, QTableWidgetItem("кг"))
        self.tableWidget.blockSignals(True)
        if self.Conrod == 1:
            if self.tableWidget.rowCount() > 7:
                row = self.tableWidget.rowCount()-1
                self.tableWidget.removeRow(row)
                row = self.tableWidget.rowCount()-1
                self.tableWidget.removeRow(row)
                row = self.tableWidget.rowCount()-1
                self.tableWidget.removeRow(row)

            row = self.tableWidget.rowCount()
            self.tableWidget.insertRow(row)
            if data['lang'] != "":
                page = data['en']['page1']
                self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][7]))
            else:
                self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Масса, приведенная к верхней головке шатуна; mw"))
            try:
                value = str(self.data.excel['mw'])
            except:
                value = ""
            self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
            if data['lang'] != "":
                self.tableWidget.setItem(row, 1, QTableWidgetItem("kg"))
            else:
                self.tableWidget.setItem(row, 1, QTableWidgetItem("кг"))

            row = self.tableWidget.rowCount()
            self.tableWidget.insertRow(row)
            if data['lang'] != "":
                page = data['en']['page1']
                self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][8]))
            else:
                self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Масса, приведенная к нижней головке шатуна; mp"))
            try:
                value = str(self.data.excel['mp'])
            except:
                value = ""
            self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
            if data['lang'] != "":
                self.tableWidget.setItem(row, 1, QTableWidgetItem("kg"))
            else:
                self.tableWidget.setItem(row, 1, QTableWidgetItem("кг"))
        elif self.Conrod == 2:
            if self.tableWidget.rowCount() > 7:
                row = self.tableWidget.rowCount()-1
                self.tableWidget.removeRow(row)
                row = self.tableWidget.rowCount()-1
                self.tableWidget.removeRow(row)
                
            row = self.tableWidget.rowCount()
            self.tableWidget.insertRow(row)
            if data['lang'] != "":
                page = data['en']['page1']
                self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][9]))
            else:
                self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Масса шатуна; MCR"))
            try:
                value = str(self.data.excel['MCR'])
            except:
                value = ""
            self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
            if data['lang'] != "":
                self.tableWidget.setItem(row, 1, QTableWidgetItem("kg"))
            else:
                self.tableWidget.setItem(row, 1, QTableWidgetItem("кг"))
            row = self.tableWidget.rowCount()
            self.tableWidget.insertRow(row)
            if data['lang'] != "":
                page = data['en']['page1']
                self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][10]))
            else:
                self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Положение центра тяжести шатуна; PCT"))
            try:
                value = str(self.data.excel['PCT'])
            except:
                value = ""
            self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
            self.tableWidget.setItem(row, 1, QTableWidgetItem("-"))
            row = self.tableWidget.rowCount()
            self.tableWidget.insertRow(row)
            if data['lang'] != "":
                page = data['en']['page1']
                self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][11]))
            else:
                self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Момент инерции шатуна; ICR"))
            try:
                value = str(self.data.excel['ICR'])
            except:
                value = ""
            self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
            if data['lang'] != "":
                self.tableWidget.setItem(row, 1, QTableWidgetItem("kg*mm^2"))
            else:
                self.tableWidget.setItem(row, 1, QTableWidgetItem("кг*мм^2"))
        self.tableWidget.blockSignals(False)
        self.tableWidget.cellChanged.connect(self.cellChange)
    def type_fuel(self):
        self.data.excel['kd'] = self.comboBox_2.currentData()
        # excel = ReadExcel(self.filename)
        self.expert.excel['kd'] = self.comboBox_2.currentData()
        # excel.updateCell('kd', self.comboBox_2.currentData(), self.filename)
    def cylinder(self):
        self.data.excel['iwar'] = self.comboBox.currentData()
        self.expert.excel['iwar'] = self.comboBox.currentData()
    def cellChange(self, row, column):
        key = self.tableWidget.verticalHeaderItem(row).text().split('; ')[1]
        if validation(self.tableWidget.item(row, column).text(), key, self.data.excel):
            self.tableWidget.blockSignals(True)
            self.tableWidget.item(row, column).setBackground(QtGui.QColor(112, 255, 127))
            self.tableWidget.blockSignals(False)
            self.expert.excel[key] = self.tableWidget.item(row, column).text()
            self.data.excel[key] = self.tableWidget.item(row, column).text()
            try:
                if self.err.error_dict[key] > 0:
                    del self.err.error_dict[key]
            except:
                pass
            if key == "nn":
                self.expert.excel['nm'] = self.tableWidget.item(row, column).text()
                self.expert.excel['nn'] = self.tableWidget.item(row, column).text()
                self.data.excel['nm'] = self.tableWidget.item(row, column).text()
                self.data.excel['nn'] = self.tableWidget.item(row, column).text()
            if key == 'DZ' or key == 'dz':
                self.expert.excel['dz'] = self.tableWidget.item(row, column).text()
                self.data.excel['dz'] = self.tableWidget.item(row, column).text()
                self.expert.excel['DZ'] = self.tableWidget.item(row, column).text()
                self.data.excel['DZ'] = self.tableWidget.item(row, column).text()
            if key == 'r' or key == 'R':
                self.expert.excel['R'] = self.tableWidget.item(row, column).text()
                self.data.excel['R'] = self.tableWidget.item(row, column).text()
                self.expert.excel['r'] = self.tableWidget.item(row, column).text()
                self.data.excel['r'] = self.tableWidget.item(row, column).text()
        else:
            self.tableWidget.blockSignals(True)
            self.tableWidget.item(row, column).setBackground(QtGui.QColor(255, 152, 152))
            self.tableWidget.blockSignals(False)
            self.err.error_dict[key] = 1
            self.err.page = 1
        
    def conrod(self):
        with open('lang.json', encoding='utf-8') as file:
            data = json.load(file)
        if data['lang'] != "":
            page = data['en']['page1']
        self.tableWidget.blockSignals(True)
        self.Conrod = self.comboBox_3.currentData()
        # excel = ReadExcel(self.filename)
        self.expert.excel['Conrod'] = self.Conrod
        # excel.updateCell('Conrod', self.Conrod, self.filename)
        self.data.excel['Conrod'] = self.Conrod
        if self.engine.cil == "V6" or self.engine.cil == "V8" or self.engine.cil == "V12":
            if self.Conrod == 1:
                if self.tableWidget.rowCount() == 10:
                    pass
                else:
                    if self.tableWidget.rowCount() > 8:
                        row = self.tableWidget.rowCount()-1
                        self.tableWidget.removeRow(row)
                        row = self.tableWidget.rowCount()-1
                        self.tableWidget.removeRow(row)
                        row = self.tableWidget.rowCount()-1
                        self.tableWidget.removeRow(row)
                    row = self.tableWidget.rowCount()
                    self.tableWidget.insertRow(row)
                    if data['lang'] != "":
                        page = data['en']['page1']
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][7]))
                    else:
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Масса, приведенная к верхней головке шатуна; mw"))
                    try:
                        value = str(self.data.excel['mw'])
                    except:
                        value = ""
                    self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
                    if data['lang'] != "":
                        self.tableWidget.setItem(row, 1, QTableWidgetItem("kg"))
                    else:
                        self.tableWidget.setItem(row, 1, QTableWidgetItem("кг"))
                    row = self.tableWidget.rowCount()
                    self.tableWidget.insertRow(row)
                    if data['lang'] != "":
                        page = data['en']['page1']
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][8]))
                    else:
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Масса, приведенная к нижней головке шатуна; mp"))
                    try:
                        value = str(self.data.excel['mp'])
                    except:
                        value = ""
                    self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
                    if data['lang'] != "":
                        self.tableWidget.setItem(row, 1, QTableWidgetItem("kg"))
                    else:
                        self.tableWidget.setItem(row, 1, QTableWidgetItem("кг"))

            elif  self.Conrod == 2:
                if self.tableWidget.rowCount() == 11:
                    pass
                else:
                    if self.tableWidget.rowCount() > 8:
                        row = self.tableWidget.rowCount()-1
                        self.tableWidget.removeRow(row)
                        row = self.tableWidget.rowCount()-1
                        self.tableWidget.removeRow(row)
                        
                    row = self.tableWidget.rowCount()
                    self.tableWidget.insertRow(row)
                    if data['lang'] != "":
                        page = data['en']['page1']
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][9]))
                    else:
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Масса шатуна; MCR"))
                    try:
                        value = str(self.data.excel['MCR'])
                    except:
                        value = ""
                    self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
                    if data['lang'] != "":
                        self.tableWidget.setItem(row, 1, QTableWidgetItem("kg"))
                    else:
                        self.tableWidget.setItem(row, 1, QTableWidgetItem("кг"))
                    row = self.tableWidget.rowCount()
                    self.tableWidget.insertRow(row)
                    if data['lang'] != "":
                        page = data['en']['page1']
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][10]))
                    else:
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Положение центра тяжести шатуна; PCT"))
                    try:
                        value = str(self.data.excel['PCT'])
                    except:
                        value = ""
                    self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
                    self.tableWidget.setItem(row, 1, QTableWidgetItem("-"))
                    row = self.tableWidget.rowCount()
                    self.tableWidget.insertRow(row)
                    if data['lang'] != "":
                        page = data['en']['page1']
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][11]))
                    else:
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Момент инерции шатуна; ICR"))
                    try:
                        value = str(self.data.excel['ICR'])
                    except:
                        value = ""
                    self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
                    if data['lang'] != "":
                        self.tableWidget.setItem(row, 1, QTableWidgetItem("kg*mm^2"))
                    else:
                        self.tableWidget.setItem(row, 1, QTableWidgetItem("кг*мм^2"))
        else:
            if self.Conrod == 1:
                if self.tableWidget.rowCount() == 9:
                    pass
                else:
                    if self.tableWidget.rowCount() > 7:
                        row = self.tableWidget.rowCount()-1
                        self.tableWidget.removeRow(row)
                        row = self.tableWidget.rowCount()-1
                        self.tableWidget.removeRow(row)
                        row = self.tableWidget.rowCount()-1
                        self.tableWidget.removeRow(row)
                    row = self.tableWidget.rowCount()
                    self.tableWidget.insertRow(row)
                    if data['lang'] != "":
                        page = data['en']['page1']
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][7]))
                    else:
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Масса, приведенная к верхней головке шатуна; mw"))
                    try:
                        value = str(self.data.excel['mw'])
                    except:
                        value = ""
                    self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
                    if data['lang'] != "":
                        self.tableWidget.setItem(row, 1, QTableWidgetItem("kg"))
                    else:
                        self.tableWidget.setItem(row, 1, QTableWidgetItem("кг"))
                    row = self.tableWidget.rowCount()
                    self.tableWidget.insertRow(row)
                    if data['lang'] != "":
                        page = data['en']['page1']
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][8]))
                    else:
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Масса, приведенная к нижней головке шатуна; mp"))
                    try:
                        value = str(self.data.excel['mp'])
                    except:
                        value = ""
                    self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
                    if data['lang'] != "":
                        self.tableWidget.setItem(row, 1, QTableWidgetItem("kg"))
                    else:
                        self.tableWidget.setItem(row, 1, QTableWidgetItem("кг"))

            elif  self.Conrod == 2:
                if self.tableWidget.rowCount() == 10:
                    pass
                else:
                    if self.tableWidget.rowCount() > 7:
                        row = self.tableWidget.rowCount()-1
                        self.tableWidget.removeRow(row)
                        row = self.tableWidget.rowCount()-1
                        self.tableWidget.removeRow(row)
                        
                    row = self.tableWidget.rowCount()
                    self.tableWidget.insertRow(row)
                    if data['lang'] != "":
                        page = data['en']['page1']
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][9]))
                    else:
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Масса шатуна; MCR"))
                    try:
                        value = str(self.data.excel['MCR'])
                    except:
                        value = ""
                    self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
                    if data['lang'] != "":
                        self.tableWidget.setItem(row, 1, QTableWidgetItem("kg"))
                    else:
                        self.tableWidget.setItem(row, 1, QTableWidgetItem("кг"))
                    row = self.tableWidget.rowCount()
                    self.tableWidget.insertRow(row)
                    if data['lang'] != "":
                        page = data['en']['page1']
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][10]))
                    else:
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Положение центра тяжести шатуна; PCT"))
                    try:
                        value = str(self.data.excel['PCT'])
                    except:
                        value = ""
                    self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
                    self.tableWidget.setItem(row, 1, QTableWidgetItem("-"))
                    row = self.tableWidget.rowCount()
                    self.tableWidget.insertRow(row)
                    if data['lang'] != "":
                        page = data['en']['page1']
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem(page['table'][11]))
                    else:
                        self.tableWidget.setVerticalHeaderItem(row, QTableWidgetItem("Момент инерции шатуна; ICR"))
                    try:
                        value = str(self.data.excel['ICR'])
                    except:
                        value = ""
                    self.tableWidget.setItem(row, 0, QTableWidgetItem(value))
                    if data['lang'] != "":
                        self.tableWidget.setItem(row, 1, QTableWidgetItem("kg*mm^2"))
                    else:
                        self.tableWidget.setItem(row, 1, QTableWidgetItem("кг*мм^2"))

        self.tableWidget.blockSignals(False)